package net.lcqf.tcp.send.message;

import cn.hutool.json.JSONUtil;
import io.netty.channel.Channel;
import net.lcqf.tcp.request.LoginRequest;
import net.lcqf.tcp.response.HeroSelectResponse;
import net.lcqf.tcp.response.LoginResponse;
import net.lcqf.tcp.response.UserInfoResponse;
import net.lcqf.tcp.send.MessageBaseService;
import net.lcqf.tcp.send.MessageFactory;
import net.lcqf.tcp.send.RequestType;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * +----------------------------------------------------------------------
 * // | Talk To [ 聊来改善地区金融服务环境，助力企业发展 ]
 * // +----------------------------------------------------------------------
 * // | Copyright (c) 2021-2025 聊来 All rights reserved.
 * // +----------------------------------------------------------------------
 * // | Licensed ( <a href="http://www.apache.org/licenses/LICENSE-2.0">apache</a> )
 * // +----------------------------------------------------------------------
 * // | @Author: 聊来 <18970881148@qq.com>
 * // +----------------------------------------------------------------------
 * // | DateTime: 2025/2/19 11:18
 * // +----------------------------------------------------------------------
 */

@Service
public class Login implements MessageBaseService {

    @Override
    @PostConstruct
    public void init() {
        MessageFactory.register(RequestType.LOGIN, this);
    }


    /**
     * TODO 未完待续
     * @param channel 消息通道
     * @param msg 内容
     * @return {@code Object}
     */
    @Override
    public Object sendMessage(Channel channel, String msg) {
        LoginRequest request = JSONUtil.toBean(msg, LoginRequest.class);

        LoginResponse login = new LoginResponse();

        UserInfoResponse userInfo = new UserInfoResponse();
        userInfo.setUserName(request.getAccount());
        userInfo.setAvatar("https://ac.lcqf.net/h5/avatar.jpg");
        userInfo.setChannelId(channel.id().asShortText());
        List<HeroSelectResponse> heroSelectData = Arrays.asList(
                new HeroSelectResponse(101),
                new HeroSelectResponse(102)
        );
        userInfo.setHeroSelectData(heroSelectData);
        login.setUserInfo(userInfo);

        login.setNotice("独断万古荒天帝");

        return login;
    }
}
